package Polymorphism;

/*
* 多态的一个例子
* */

class Shape {


    public void draw() {
        System.out.println("画图形!");
    }
}
class Rect extends Shape {
    @Override
    public void draw() {
        System.out.println("◆");
    }
}
class Cycle extends Shape {
    @Override
    public void draw() {
        System.out.println("○");
    }
}


public class Test5 {

    public static void drawMap(Shape shape) {
        shape.draw();
    }

    public static void main(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Shape[] shapes = {rect,cycle,cycle,rect};//运用多态减少if else的使用 降低圈复杂度
        for (Shape shape : shapes) {
            drawMap(shape);
        }
    }
    public static void main1(String[] args) {

        Shape shape = new Shape();
        Rect rect = new Rect();
        Cycle cycle = new Cycle();

        drawMap(shape);
        drawMap(rect);
        drawMap(cycle);
    }
}
